package classfile

import (
	. "jvm/typedef"
)

type BytecodeReader struct {
	bytecode []byte
}



// ***********************************************
// private
func newBytecodeReader(bytecode []byte) *BytecodeReader {
	bytecodeReader := BytecodeReader{
		bytecode: bytecode,
	}
	return &bytecodeReader
}
func (self *BytecodeReader) readU1() U1 {
	var data U1
	data = U1(self.bytecode[0])
	self.bytecode = self.bytecode[1:]
	return data
}
func (self *BytecodeReader) readU2() U2 {
	var data U2
	data = (U2(self.bytecode[0]))<<8 | U2(self.bytecode[1])
	self.bytecode = self.bytecode[2:]
	return data
}

func (self *BytecodeReader) readU4() U4 {
	var data U4
	data = (U4(self.bytecode[0]))<<24 |
		(U4(self.bytecode[1]))<<16 |
		(U4(self.bytecode[2]))<<8 |
		(U4(self.bytecode[3]))
	self.bytecode = self.bytecode[4:]
	return data
}

func (self *BytecodeReader) readU8() U8 {
	high := self.readU4()
	low := self.readU4()
	data := U8(high) << 32 | U8(low)
	return data
}

func (self *BytecodeReader) readBytes(len uint32) []byte {
	data := self.bytecode[:len]
	self.bytecode = self.bytecode[len:]
	return data
}
//***********************************************
